package com.example.util;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 全局返回实体类
 *
 * @author 10313
 */
public class Result extends HashMap<String, Object> implements Serializable {

    private static final long serialVersionUID = -3575148332132548735L;

    public Result() {
        this.put("code", "0000");
        this.put("msg", "success");
    }

    public static Result error() {
        return error("500", "未知异常，请联系管理员");
    }

    public static Result error(String msg) {
        return error("500", msg);
    }

    public static Result error(String code, String msg) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static Result ok(String msg) {
        Result result = new Result();
        result.put("msg", msg);
        return result;
    }

    public static Result ok(Map<String, Object> map) {
        Result result = new Result();
        result.putAll(map);
        return result;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
